<template>
  <a-spin :spinning="confirmLoading">
    <j-form-container :disabled="formDisabled">
      <a-form-model ref="form" :model="model" :rules="validatorRules" slot="detail">
        <a-row>
          <a-col :span="24">
            <a-form-model-item label="店主ID" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="sellerId">
              <j-search-select-tag v-model="model.sellerId" dict="ht_merchant,enterprise_name,id"  />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="IM用户ID-关联客服" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="imUserId">
              <j-search-select-tag v-model="model.imUserId" dict="im_user,nickname,id"  />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="管理员ID" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="sysUserId">
              <j-search-select-tag v-model="model.sysUserId" dict="sys_user,username,id"  />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="店铺名称" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="name">
              <a-input v-model="model.name" placeholder="请输入店铺名称"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="店铺logo" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="logo">
              <a-input v-model="model.logo" placeholder="请输入店铺logo"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="店铺信息" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="introduction">
              <j-editor v-model="model.introduction" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="行业分类ID" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="industryCategoryId">
              <a-input v-model="model.industryCategoryId" placeholder="请输入行业分类ID"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="店铺地址ID" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="shopAddressId">
              <a-input v-model="model.shopAddressId" placeholder="请输入店铺地址ID"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="发货地址ID" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="sellerAddressId">
              <a-input v-model="model.sellerAddressId" placeholder="请输入发货地址ID"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="店铺认证：0-未认证 1-认证中 2-已认证 3-已驳回" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="auditStatus">
              <a-input-number v-model="model.auditStatus" placeholder="请输入店铺认证：0-未认证 1-认证中 2-已认证 3-已驳回" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="认证审批人" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="auditUsername">
              <a-input v-model="model.auditUsername" placeholder="请输入认证审批人"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="认证审批意见" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="auditComments">
              <a-textarea v-model="model.auditComments" rows="4" placeholder="请输入认证审批意见" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="邮箱" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="email">
              <a-input v-model="model.email" placeholder="请输入邮箱"  ></a-input>
            </a-form-model-item>
          </a-col>
        </a-row>
      </a-form-model>
    </j-form-container>
  </a-spin>
</template>

<script>

  import { httpAction, getAction } from '@/api/manage'
  import { validateDuplicateValue } from '@/utils/util'

  export default {
    name: 'HTShopForm',
    components: {
    },
    props: {
      //表单禁用
      disabled: {
        type: Boolean,
        default: false,
        required: false
      }
    },
    data () {
      return {
        model:{
         },
        labelCol: {
          xs: { span: 24 },
          sm: { span: 5 },
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 16 },
        },
        confirmLoading: false,
        validatorRules: {
           sellerId: [
              { required: true, message: '请输入店主ID!'},
           ],
           name: [
              { required: true, message: '请输入店铺名称!'},
           ],
           logo: [
              { required: true, message: '请输入店铺logo!'},
           ],
           industryCategoryId: [
              { required: true, message: '请输入行业分类ID!'},
           ],
           auditStatus: [
              { required: true, message: '请输入店铺认证：0-未认证 1-认证中 2-已认证 3-已驳回!'},
           ],
        },
        url: {
          add: "/shop/hTShop/add",
          edit: "/shop/hTShop/edit",
          queryById: "/shop/hTShop/queryById"
        }
      }
    },
    computed: {
      formDisabled(){
        return this.disabled
      },
    },
    created () {
       //备份model原始值
      this.modelDefault = JSON.parse(JSON.stringify(this.model));
    },
    methods: {
      add () {
        this.edit(this.modelDefault);
      },
      edit (record) {
        this.model = Object.assign({}, record);
        this.visible = true;
      },
      submitForm () {
        const that = this;
        // 触发表单验证
        this.$refs.form.validate(valid => {
          if (valid) {
            that.confirmLoading = true;
            let httpurl = '';
            let method = '';
            if(!this.model.id){
              httpurl+=this.url.add;
              method = 'post';
            }else{
              httpurl+=this.url.edit;
               method = 'put';
            }
            httpAction(httpurl,this.model,method).then((res)=>{
              if(res.success){
                that.$message.success(res.message);
                that.$emit('ok');
              }else{
                that.$message.warning(res.message);
              }
            }).finally(() => {
              that.confirmLoading = false;
            })
          }
         
        })
      },
    }
  }
</script>